package com.fhz.day005.fragment;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.fhz.day005.R;


public class UpFragment extends Fragment {

    private EditText upFgEdit;
    private Button upBtn;

    public interface MyListener{
        void click(String s);
    }

    private MyListener myListener;

    public void setMyListener(MyListener myListener) {
        this.myListener = myListener;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View inflate = inflater.inflate(R.layout.fragment_up, container, false);

        upFgEdit = (EditText) inflate.findViewById(R.id.up_fg_edit);
        upBtn = (Button) inflate.findViewById(R.id.up_btn);

        upBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //要找到需要接收值的fragment
//                myListener = (MyListener) getFragmentManager().findFragmentById(R.id.down_fg1);
                myListener = (MyListener) getFragmentManager().findFragmentByTag("up");
                String s = upFgEdit.getText().toString();
                myListener.click(s);
            }
        });


        return inflate;
    }
}